package com.itheima.response;

import javax.servlet.ServletException;
import javax.servlet.ServletOutputStream;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.*;

@WebServlet("/response/demo03")
public class ServletDemo03 extends HttpServlet {

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        resp.setDateHeader("Expires",(System.currentTimeMillis()+1*60*60*1000L));
        BufferedInputStream bis = new BufferedInputStream(new FileInputStream("d://美女.jpg"));

        ServletOutputStream os = resp.getOutputStream();
        BufferedOutputStream bos = new BufferedOutputStream(os);
        int len;
        byte[] bytes=new byte[1024];
        while ((len=bis.read(bytes))!=-1){
            bos.write(bytes,0,len);
        }

        bis.close();
        bos.close();
        System.out.println("有人来看过了");
        //resp.setDateHeader("Expires",System.currentTimeMillis()+3600*1000);
    }


    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doGet(req, resp);
    }
}
